package client_listen_update_files;


import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.UnsupportedEncodingException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Node;

import dropbox.common.Utils;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws UnsupportedEncodingException {
	//System.out.println(Utils.getCheckSum(new File("C:\\temp\\changed1.txt")));
		new FolderListener().run();
	}
	
/*
		Config config=new Config();
		config.setDropBoxPath("C:\\temp\\dropbox");
		config.setUserName("yoavip@hotmail.com");
		config.setPassword("1234567");
				
		 XMLEncoder e;
		try {
			e = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(new File("DBconfig.xml"))));
			
		  e.writeObject(config);
		 e.close();
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
	}
*/

		
		/*
		DefaultHttpClient httpclient = new DefaultHttpClient();
		HttpRequestInterceptor preemtiveAuth = new HttpRequestInterceptor() {
			   @Override
			   public void process(HttpRequest req, HttpContext context)
			     throws HttpException, IOException {
			    req.addHeader(new BasicScheme()
			     .authenticate(new UsernamePasswordCredentials("yoavip@hotmail.com","1234567"), req));			    
			   }
		 };;
		 
	
			  
		httpclient.getParams().setParameter(
				CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
		httpclient.addRequestInterceptor(preemtiveAuth,0);
		//List<NameValuePair> nameValuePairs=setUserInfo();		
		//nameValuePairs.add(new BasicNameValuePair("checkSum", String.valueOf(checkSum)));
		HttpPost httppost = new HttpPost("http://localhost:9991/ChkExists");
		//httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
		try {
			HttpResponse response = httpclient.execute(httppost);
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		 /*
		HttpClient httpclient = new DefaultHttpClient();
	    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
	    HttpPost httppost = new HttpPost("http://localhost:9991/Download");
	    
	    
	    System.out.println("executing request " + httppost.getRequestLine());
		
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();		
		nameValuePairs.add(new BasicNameValuePair("userName", "yoavip@hotmail.com"));
		nameValuePairs.add(new BasicNameValuePair("password","1234567"));	
		nameValuePairs.add(new BasicNameValuePair("checkSum","0"));
		try {
			httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
		
		
		HttpResponse response;
		response = httpclient.execute(httppost);
    	BufferedInputStream in=new BufferedInputStream(response.getEntity().getContent());
    	BufferedOutputStream out=new BufferedOutputStream(new FileOutputStream(new File("C:\\temp\\download\\temp.rar")));
    	byte[] buffer = new byte[4096];
    	int byteRead=0;
		while ((in != null) && ((byteRead = in.read(buffer)) != -1)) {
			out.write(buffer, 0, byteRead);
		}	
		in.close();
		out.close();
		if (response.getEntity() != null) {
		
				EntityUtils.consume(response.getEntity());
			
		
		}
	}catch (IOException e){
		e.printStackTrace();
	}
	}
	*/ 
}


    	
      
    
    
		

